import java.util.Stack;

public class Test05 {
    public static String decodeString(String s) {


        Stack<Character> stack1 = new Stack<>();   //这个是放数字的
        Stack<StringBuilder> stack2 = new Stack<>();  //这个是放除了数字的
        stack2.push(new StringBuilder());
        StringBuilder str = new StringBuilder();
        for(int i = 0;i<s.length();){
            if(s.charAt(i)>='0'&&s.charAt(i)<='9'){
                int tmp = 0;
                while(i<s.length()&&s.charAt(i)>='0'&&s.charAt(i)<='9'){
                    tmp = tmp*10+(s.charAt(i)-'0');
                    i++;
                }
                stack1.push(s.charAt(i));
            }
            else if(s.charAt(i)=='['){
                i++;
                StringBuilder tmp = new StringBuilder();
                while(i<s.length()&&s.charAt(i)>='a'&&s.charAt(i)<='z'){
                    tmp.append(s.charAt(i));
                    i++;
                }
                stack2.push(tmp);
            }else if(s.charAt(i)==']'){
                StringBuilder str3 = stack2.pop();
                int count = stack1.pop()-'0';
                while(count>0){
                    stack2.peek().append(str3);
                    count--;
                }
                i++;
            }else{

                StringBuilder tmp = new StringBuilder();
                while(i<s.length()&&s.charAt(i)>='a'&&s.charAt(i)<='z'){
                    tmp.append(s.charAt(i));
                    i++;
                }
                stack2.push(tmp);

            }
        }
        return stack2.pop().toString();
    }
    public static void main(String[] args) {
        String  s = decodeString("3[a]2[bc]");
        System.out.println("s");
        char a = '2';
        char b = '1';
        char c  =(char) (a-b);
        System.out.println(c);
        Stack<StringBuilder> stringBuilders = new Stack<>();
        stringBuilders.push(new StringBuilder("12"));
        stringBuilders.peek().append("333");
        System.out.println(stringBuilders.pop());


    }
}
